package com.tedu.egmvc4.controller;

import com.tedu.egmvc4.mapper.AddressMapper;
import com.tedu.egmvc4.pojo.dto.param.AddressAddParam;
import com.tedu.egmvc4.pojo.entity.Address;
import com.tedu.egmvc4.pojo.vo.AddressInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @PostMapping("add")
    public String add(AddressAddParam addressAddParam){
        System.out.println("添加地址："+addressAddParam);
        Address address=new Address();
        BeanUtils.copyProperties(addressAddParam,address);
        addressMapper.insert(address);
        return "添加地址成功";
    }
    @GetMapping("list")
    public List<AddressInfoVO > list(){
        System.out.println("查询地址列表");
        List<AddressInfoVO>addressInfoVOS=addressMapper.list();
        return addressInfoVOS;
    }
    @PostMapping("delete")
    public String delete(Integer id){
        System.out.println("删除地址："+id);
        addressMapper.delete(id);
        return "删除地址成功";
    }
}
